package com.student;

import java.util.HashMap;
import java.util.Map;
import com.student.Person;
public class Student extends Person implements PrintInformation{
    private Map<String, Double> grade = new HashMap<>();
    public Student(String name1, int age1, String gender1, int classId1){
        name = name1;
        age = age1;
        gender = gender1;
        classId = classId1;
    }
    //打印个人信息：
    public void printf(){
        System.out.printf("姓名：%s\n年龄：%d\n性别：%s\n班级：%d\n", name, age, gender, classId);
        try{
            if(grade.isEmpty()){
                throw new IllegalArgumentException("成绩不存在");
            }
            for(Map.Entry<String, Double> mapset: grade.entrySet()){
                System.out.printf("课程：%s,成绩：%.2f\t", mapset.getKey(), mapset.getValue());
            }
        }
        catch (IllegalArgumentException e){
           System.out.println(e.getMessage());
        }

    }
    //添加成绩
    public void addGrade(String className, double grade1){
        if(grade.containsKey(className)){
            grade.replace(className, grade1);
        }else{
            grade.put(className, grade1);
        }
        System.out.println("成绩添加成功");
    }
    public void deleteGrade(String className){
        if(grade.containsKey(className)){
            grade.remove(className);
        }
        else{
            System.out.println("该学生没有这门成绩");
        }
    }
}